/*=====================================================
 Copyright (C) ETERNAL<iqstar@ms24.hinet.net>
 URL : http://www.et99.net

请仔细阅读以下许可协议。当您使用本软体，您将自动成为本协议的一方并受到本协议的约束。

软体和文档受到台湾及中国大陆著作权法及国际条约的保护。您不得：
a)营利、出租或者出借软体或文档的任何部分。
b)反向工程、分解、反编译或者企图察看软体的源代码作为商业用途。
c)修改或者改变软体，或者与其他程式结合。

许可人保留软体及文档的所有权利和权益。您不能通过本许可协定获得软体的任何所有权和知识产权。
===================================================== */
function setup_mname(name) {
    m_name = name;
};

function setup_jmmoney(money) {
    cp_jmmoney = money;
};

function get_name() {
    return p_name;
};

function get_mname() {
    return m_name;
};

//##### page head begin #####
function message_cls(a, bline) {
    f = parent.wog_view.document;
    if (bline == null) {
        bline = 2;
    }
    if (a != null) {
        a.close();
        a.write('<html>');
        a.write('<head>');
        a.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
        a.write('<meta http-equiv=Cache-Control content="no-cache">');
        a.write('<style type=text/css>');
        a.write('td {font-family : verdana,Arial,Helvetica ;font-size : 12px;text-align : center;}');
        a.write('.b1 {text-align : left;}');
        a.write('.a1 {text-align : center;}');
        a.write('</style>');
        a.write('</head>');
        a.write('<body>');
    } else {
        set_window();
        _docWidth = UI.window_w;
        _docHeight = UI.window_h;
        var online_top = 0;
        var online_left = _docWidth - 155;
        var menu_top = _docHeight - 118;
        var menu_left = 0;
        var chat_top = _docHeight - 182;
        var chat_left = 330;
        f.close();
        f.write('<html>');
        f.write('<head>');
        f.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>');
        f.write('<meta http-equiv=Cache-Control content="no-cache"/>');
        f.write('<link href="./css/wog.css?t="' + new Date().getTime() + ' rel="stylesheet"/>');
        f.write('<link href="./css/wog_infinity/main.css?t=' + new Date().getTime() + '" rel="stylesheet"/>');
        f.write('</head>');
        f.write('<body id="scrollbar-inner">');
        f.write('<div id="wog_center_all" onclick="parent.lay_show(\'wog_center_all\')"><table><tr><td"><div class="wog-center " id="wog_center" ></div></td></tr></table></div>');
        f.write('<div id="wog_menu" onclick="parent.lay_show(\'wog_menu\')"></div>');
        f.write('<div id="wog_chat" onclick="parent.lay_show(\'wog_chat\')"></div>');
        // f.write('<div id="wog_online" onclick="parent.lay_show(\'wog_online\')" style="position:absolute; left:'+online_left+'px; top:'+online_top+'px;Z-INDEX: 200"></div>');
        f.write('<div id="wog_select"></div>');
        f.write('<div id="wog_well_box"></div>');
        f.write('<div id="wog_message_box"></div>');
        f.write('<div id="wog_chat_set"></div>');
        f.write('<div id="wog_mercenary_job" class="wog-mercenary-job"></div>');
        f.write('<script src="./js/jquery-3.5.1.min.js"></script>');
        f.write(`<script>
    function toggleFightSetting(){
        $('#fightSetting').stop(true).toggle()
    }
        $(document).on('click','.fight-category',function() {
            console.log('input:radio[name="a_type"][value='+$(this).data('a_type')+']')
            $('input:radio[name="a_type"][value="'+$(this).data('a_type')+'"]').prop('checked',true);
            $(this).addClass('selected');
            $('.fight-category').not($(this)).removeClass('selected');
        })
</script>`);
        f.write('</body></html>')
    }
}

function p_s(x, y, z) {
    var w = 350;
    if (z) {
        w = z;
    }
    f.getElementById("wog_select").innerHTML = '<form action="wog_group.php" method="post" name="f102" target="mission"><table width="' + w + '" border="0" cellspacing="0" cellpadding="1" bgcolor=' + tr_bgcolor2 + '><tr><td width="100%">' + wog_center_html + '</td></tr></table></form>';
    wog_center_html = "";
    if (!x) {
        x = UI.mouse_x;
    }
    if (!y) {
        y = UI.mouse_y;
    }
    set_div_x_y(x + 15, y - 20, "wog_select");
};

function p_as(x, y, z) {
    var w = 350;
    if (z) {
        w = z;
    }
    f.getElementById("wog_select").innerHTML = '<form action="wog_act.php" method="post" name="f101" target="mission">' + wog_center_html + '</form>';
    wog_center_html = "";
    if (!x) {
        x = UI.mouse_x;
    }
    if (!y) {
        y = UI.mouse_y;
    }
    set_div_x_y(x + 15, y - 20, "wog_select");
};

function w_c(a) {
    wog_center_html += a;
};

function w_o(a) {
    wog_online_list_html += a;
};

function w_m(a) {
    wog_menu_html += a;
};

function w_chat(a) {
    wog_chat_html += a;
};

/**
 * 将html渲染到wog_center
 */
function p_c() {
    var center = f.getElementById('wog_center');
    center.innerHTML = wog_center_html;
    wog_center_html = "";
}

function p_nc() {
    if (f.getElementById("a4")) {
        f.getElementById("a4").innerHTML += wog_center_html;
    } else {
        f.getElementById("wog_center").innerHTML += wog_center_html;
    }
    wog_center_html = "";
};

function p_o() {
    f = parent.wog_view.document;
    if (f.getElementById("wog_online")) {
        f.getElementById("wog_online").innerHTML = wog_online_list_html;
    }
    wog_online_list_html = "";
};

function p_m() {
    if (UI.set_frame == 1) {
        f.getElementById("wog_menu").innerHTML = wog_menu_html;
    } else {
        dfoot.getElementById("wog_menu").innerHTML = wog_menu_html;
    }
    wog_menu_html = "";
};

function p_chat() {
    if (UI.set_frame == 1) {
        f.getElementById("wog_chat").innerHTML = wog_chat_html;
    } else if (parent.document.getElementById('wog_chat')) {
        parent.document.getElementById('wog_chat').contentWindow.document.getElementById("wog_chat").innerHTML = wog_chat_html;
    }
    wog_chat_html = "";
};

function p_s_close() {
    f.getElementById("wog_select").innerHTML = '';
};

function lay_show(a) {
    f.getElementById("wog_center_all").style.zIndex = "1";
    f.getElementById("wog_menu").style.zIndex = "202";
    f.getElementById("wog_chat").style.zIndex = "198";
    if (a != '') {
        f.getElementById(a).style.zIndex = "300";
    }
};

//###### tip message ######
function job_end(a, message, type, item_id, item_num) {
    if (a == 2) {
        d_a_name = "";
        d_body_name = "";
        d_head_name = "";
        d_hand_name = "";
        d_foot_name = "";
        d_item_name = "";
        d_item2_name = "";
    }
    var temp = '';
    temp = '<br>' + temp_table1 + '<tr bgcolor=' + tr_bgcolor2 + '><td>' + job_s[a] + '!!</td></tr>';
    if (message) {
        while (message.indexOf("&n") > 0) {
            message = message.replace("&n", "<br>");
        }
        temp += '<tr><td>' + message + '</td></tr>';
    }
    temp += temp_table2;
    if (type) {
        switch (type) {
            case 1:
                if (item_id != null) {
                    if (item_num) {
                        var o_num = f.getElementById("show_message_" + item_id).innerHTML;
                        item_num = parseInt(o_num) - item_num;
                        if (item_num > 0) {

                            f.getElementById("show_message_" + item_id).innerHTML = item_num;
                        } else {
                            act_click('arm', 'view', localStorage.getItem('d_type'))
                        }
                    }
                }
                if (a > 0) {
                    f.getElementById("show_message").innerHTML = temp;
                }
                break;
            case 2:
                w_c(temp);
                p_nc();
                break;
            case 3:
                temp = temp_table1 + '<tr bgcolor=' + tr_bgcolor2 + '><td>' + job_s[a] + '</td></tr>' + temp_table2 + '<a href="javascript:parent.p_s_close();" target="mission">关闭</a>';
                w_c(temp);
                p_as();
                break;
        }
    } else {
        w_c(temp);
        p_c();
    }
};

function try_login() {
    if (parent.foot.document.f1) {
        var a = parent.foot.document.f1;
        a.f.value = "chara";
        a.act.value = "try_login";
        a.submit();
    } else {
        window.setTimeout("try_login()", 1000);
    }
};

function p1() {
    parent.peolist.document.location = "wog_etc.php?f=peo";
};

function mercenary_start() {
    if (mercenary_set == 1) {
        parent.peolist.document.location = "wog_etc.php?f=mercenary";
    }
};

function mercenary_f() {
    job_work.mercenary_start = setInterval("mercenary_start()", mercenary_time);
};

/**
 * 判断浏览器端
 */
function isMobileDevice() {
    return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);

}

/**
 * 自动执行移动端添加class
 * @param id
 * @param className
 */
function mobileScreenAddClass(id, className) {
    window.onload = function () {
        var device = isMobileDevice();
        console.log(device)
        console.log(id, className)
        var el = document.getElementById(id);
        console.log(el)
        var class_o_name = el.getAttribute('class');
        isMobileDevice() ? class_o_name += ' ' + className : '';
        el.setAttribute('class', class_o_name)
    }
}